package com.wind.stream;

import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * Stream创建的三种方式
 *
 * @author Wind
 * @date 2021-06-06
 */
public class Test01Stream {
    public static void main(String[] args) {
        /*
            1. Collection集合创建流
         */
        List<String> list = Arrays.asList("1", "2", "3", "4", "5");
        // 创建一个顺序流
        Stream<String> stream = list.stream();
        // 创建一个并行流
        Stream<String> parallelStream = list.parallelStream();

        /*
            2. 数组创建流
         */
        int[] array = {1, 2, 3, 4, 5};
        IntStream arrayStream = Arrays.stream(array);

        /*
            3. 使用Stream的静态方法：of()、iterate()、generate()
         */
        // of()
        Stream<Integer> integerStream = Stream.of(1, 2, 3, 4, 5);
        // iterate()
        Stream<Integer> limitStream = Stream.iterate(0, x -> x + 1).limit(4);   // 从0开始，每次+1，循环4次
        // generate()
        String[] arrString = {"1", "2", "3"};
        Stream<String[]> generateStream = Stream.generate(() -> arrString);

    }
}
